${page.setTitle("push-center| GOPS")}
<div class="body-pla-content">
	<div class="s-table-wapper">
	<form action="">
		<table class="s-table">
			<tr>
				<td>
					对应模板：
				</td>
				<td>
					<input type="text" name="templateId"  id="templateId" value="${templateId!}"/>
				</td>
				<td><input id="btnSearch"  type="button" value="查询"  class="l-button"/>
				<input type="reset" value="清空" class="l-button l-button-reset"/> 
				</td>	
			</tr>
			
		</table>
		</form>
	</div>
	<div id="maingrid" style="margin:0; padding:0"></div>
	<div style="display:none;">
</div>



<script type="text/javascript">


var grid;
$(function () {
     var columns= [
       				{ display: 'ID', name: 'id', width: 30},
       				{ display: '应用模版名', name: 'name', width: 100,render: function (item){
			   				return "<a title='"+item.name+"'>"+item.name+"</a>";
			  			}
			  		},
       				{ display: '模版名', name: 'templateName', width: 100,render: function (item){
			   				return "<a title='"+item.templateName+"'>"+item.templateName+"</a>";
			  			}
			  		},
       				
       				{ display: 'appId', name: 'appId', width: 100},
       				
       				{ display: '外部模板id', name: 'extTemplId', width: 100,render: function (item){
			   				return "<a title='"+item.extTemplId+"'>"+item.extTemplId+"</a>";
			  			}
			  		},
			  		{ display: '模板ID', name: 'templateId', width: 40},
       				{ display: '域ID', name: 'domainId', width: 40},
       				{ display: '渠道ID', name: 'appChannelId', width: 40},
       				{ display: '优先级', name: 'priority', width: 60},
       				{ display: '发送渠道', name: 'appChannel', render:epay_enum.channels.type.render},
       				{ display: '对应关系', name: 'paramConvert', width: 100},
       				{ display: '指定模板', name: 'text', width: 100,render: function (item){
			   				return "<a title='"+item.text+"'>"+item.text+"</a>";
			  			}
			  		},
       				{ display: '修改时间', name: 'gmtModified', width: 100,type:"datetime2"},
       				{ display: '备注', name: 'memo'}
                   ];
     var toolbar={
		 items: [
			 {text: '增加', click: toolbarBtnItemClick, icon:'add'},
			 { line:true },
			 { text: '修改', click: toolbarBtnItemClick,icon:'modify'},
			 { line:true },
			 { text: '删除', click: toolbarBtnItemClick,icon:'delete'},
			 { line:true },
			 {text: '更新状态', click: toolbarBtnItemClick, icon:'refresh'}
		]
     };
    	
	grid = $("#maingrid").ligerGrid({
						columns:columns,
						toolbar:toolbar,
						checkbox:true,
						enabledSort:false,
						pageSize:15,
						dataAction:'server',
						root:'rows',
						record :'total',
						pageParmName :'page',
						pagesizeParmName :'pageSize',
						width: '100%',
						height:'90%',
						url:'${appServer}/apptemplate/query.json',
						parms : $("form").serializeArray(),
						method:'get',
						onSuccess:function(data, grid){
							if(data.hasError){
								$.ligerDialog.error(data.message);
							}
						}
					});
     	
     $("#pageloading").hide();
     
      $("#btnSearch").click(function(){
		 search();
	 });
});

function search(){
	 var appKey=$("#appKey");
 	 grid.setOptions( {
 		  		url: '${appServer}/apptemplate/query.json',
 		  		pageSize:15,
 		  		page:1,
 		  		dataAction:'server',
                parms : $("form").serializeArray(),
                delayLoad : true,
			    root:'rows',
			    record :'total',
			    pageParmName :'page',
				pagesizeParmName :'pageSize' 
         });
}

//工具条事件
function toolbarBtnItemClick(item) {
	var url= null;
    switch (item.icon) {
        case "add":
        	url= "${appServer}/apptemplate/add";
        	openWindow(url, '添加', 700, 500);  
            break;
        case "modify":
        	var data = grid.getCheckedRows();
            if (data.length != 1){
                $.ligerDialog.error('请选择一条需要修改的记录!');
                return;
            }
            url = "${appServer}/apptemplate/update/"+data[0].id;
        	openWindow(url, '修改', 700, 500);  
            break;
        case "delete":
        	var data = grid.getCheckedRows();
            if (data.length != 1){
                $.ligerDialog.error('请选择一条需要删除的记录!');
                return;
            }
            jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
                if (confirm){
                	  $.ajax({
              	        url: "${appServer}/apptemplate/delete.json",   
              	        data: {id:data[0].id}, 
              	        type: "POST",
              	        success: function(result) {
              	        	if(result.hasError) {
              					$.ligerDialog.error(result.message);
              	        	}else{
              	        		$.ligerDialog.success(result.message);
              	        		window.search();
              	        	}
              	        }
              	    });
                 }
            });
            break;
            case "refresh":
            jQuery.ligerDialog.confirm('确定要刷新缓存么？', function (confirm) {
                if (confirm){
                	  $.ajax({
              	        url: "${appServer}/apptemplate/refresh.json",   
              	        type: "get",
              	        success: function(result) {
              	        	if(result.hasError) {
              					$.ligerDialog.error(result.message);
              	        	}else{
              	        		$.ligerDialog.success(result.message);
              	        		window.search();
              	        	}
              	        }
              	    });
                 }
            });
            break;
    }
}

var template_columns = [
		{ header: 'ID', name: 'id', width: 20 },
		{ header: '模板标题', name: 'title', width: 120 },
		{ header: '模板配置', name: 'text' , width: 120},
		{ header: '业务优先级', name: 'priority', width: 120 }
];

 
  
   //-------------------template ----------------------
	 
	  $(function ()
        { 
            $("#templateId").ligerComboBox({
                onBeforeOpen: f_selectContact,width:135
            });
        });
        function f_selectContact()
        {
            $.ligerDialog.open({ title: ' ++选择模板_ID', name:'winselector',width: 550, height: 400,  url: '${appServer}/template/list-alltemplate', buttons: [
                { text: '确定', onclick: f_selectContactOK },
                { text: '取消', onclick: f_selectContactCancel }
            ]
            });
            return false;
        }
        function f_selectContactOK(item, dialog)
        {
			var fn = dialog.frame.f_select || dialog.frame.window.f_select; 
            var data = fn(); 
            if (!data)
            {
                alert('请选择行!');
                return;
            }
            $("#templateId").val(data.id);
            dialog.close();
        }
        function f_selectContactCancel(item, dialog)
        {
            dialog.close();
        }
	 //-------------------tempate end!!!----------------
	 
	 //-----------------domain_start -----------
 $(function ()
        { 
            $("#domainId").ligerComboBox({
                onBeforeOpen: f_selectContact3, width:135
            });
        });
        function f_selectContact3()
        {
            $.ligerDialog.open({ title: ' ++选择域', name:'winselector',width: 550, height: 400,  url: '${appServer}/domain/listall-domain', buttons: [
                { text: '确定', onclick: f_selectContactOK3 },
                { text: '取消', onclick: f_selectContactCancel3 }
            ]
            });
            return false;
        }
        function f_selectContactOK3(item, dialog)
        {
			var fn = dialog.frame.f_select || dialog.frame.window.f_select; 
            var data = fn(); 
            if (!data)
            {
                alert('请选择行!');
                return;
            }
            $("#domainId").val(data.id);
            dialog.close();
        }
        function f_selectContactCancel3(item, dialog)
        {
            dialog.close();
        }
	
	
	//------------------------domain---------end
</script>
